from flask import Blueprint
from flask import redirect
from flask import request
from flask import session

admin_blue = Blueprint("admin",__name__,url_prefix="/admin")

from . import views

#使用请求钩子拦截普通用户
#拦截的是访问了admin所装饰的视图函数
@admin_blue.before_request
def before_request():
    #判断访问的是否是登陆页面
    # if request.url.endswith("/admin/login"):
    #     pass
    # else:
    #     #判断是否是管理员
    #     if session.get("is_admin"):
    #         pass
    #     else:
    #         return redirect("/")


    #优化
    if not request.url.endswith("/admin/login"):
        if not session.get("is_admin"):
            return redirect("/")